// 订单相关API封装
import request from './request'

// 创建订单（从购物车）
export const createOrder = (data) => {
  return request({
    url: '/order/create',
    method: 'post',
    data
  })
}

// 直接下单
export const createDirectOrder = (data) => {
  return request({
    url: '/order/createDirect',
    method: 'post',
    data
  })
}

// 获取订单详情（通过ID）
export const getOrderDetail = (orderId) => {
  return request({
    url: `/order/${orderId}`,
    method: 'get'
  })
}

// 获取订单详情（通过订单号）
export const getOrderDetailByOrderNo = (orderNo) => {
  return request({
    url: `/order/detail/${orderNo}`,
    method: 'get'
  })
}

// 获取用户订单列表
export const getUserOrderList = (params) => {
  return request({
    url: '/order/list',
    method: 'get',
    params
  })
}

// 取消订单（通过ID）
export const cancelOrder = (orderId) => {
  return request({
    url: `/order/cancel/${orderId}`,
    method: 'put'
  })
}

// 取消订单（通过订单号）
export const cancelOrderByOrderNo = (orderNo) => {
  return request({
    url: `/order/cancel/orderNo/${orderNo}`,
    method: 'put'
    })
}
// 管理端：分页查询订单列表
export const getAdminOrderList = (params) => {
  return request({
    url: '/admin/order/list',
    method: 'get',
    params
  })
}

// 管理端：新增订单
export const addAdminOrder = (data) => {
  return request({
    url: '/admin/order',
    method: 'post',
    data
  })
}

// 管理端：编辑订单
export const updateAdminOrder = (id, data) => {
  return request({
    url: `/admin/order/${id}`,
    method: 'put',
    data
  })
}

// 管理端：删除订单
export const deleteAdminOrder = (id) => {
  return request({
    url: `/admin/order/${id}`,
    method: 'delete'
  })
}

// 管理端：获取订单详情
export const getAdminOrderDetail = (id) => {
  return request({
    url: `/admin/order/${id}`,
    method: 'get'
  })
}

// 获取订单统计信息
export const getOrderStatistics = () => {
  return request({
    url: '/order/statistics',
    method: 'get'
  })
}